package com.steveproject.parttimeworktree.utils;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;

import java.util.HashMap;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;

public class NewsShareUtils {
    /**
     * 分享图片 到微信好友
     */
    public static void shareImgToFriends(Context context, Bitmap bp) {
        OnekeyShare oks = new OnekeyShare();
        oks.disableSSOWhenAuthorize();
        oks.setImageData(bp);
        oks.setPlatform(Wechat.NAME);
        oks.setCallback(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
            }

            @Override
            public void onError(Platform platform, int i, Throwable throwable) {

            }

            @Override
            public void onCancel(Platform platform, int i) {
            }
        });
        oks.show(context);
    }

    /**
     * 分享图片 到微信朋友圈
     */
    public static void shareImgToCircleFriends(Context context, Bitmap bp) {
        OnekeyShare oks = new OnekeyShare();
        oks.disableSSOWhenAuthorize();
        oks.setImageData(bp);
        oks.setPlatform(WechatMoments.NAME);
        oks.setCallback(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
            }

            @Override
            public void onError(Platform platform, int i, Throwable throwable) {

            }

            @Override
            public void onCancel(Platform platform, int i) {
            }
        });
        oks.show(context);
    }


    /**
     * 分享链接 到微信朋友圈
     */
    public static void shareUrlToCircleFriends(Context context, String title, String url, String imgUrl) {
        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();

        // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间等使用
        oks.setTitle(title);
        oks.setImageUrl(imgUrl);
        oks.setText(url);
        oks.setUrl(url);
        oks.setSiteUrl(imgUrl);
        oks.setPlatform(WechatMoments.NAME);
        oks.setCallback(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

            }

            @Override
            public void onError(Platform platform, int i, Throwable throwable) {

            }

            @Override
            public void onCancel(Platform platform, int i) {

            }
        });
        oks.show(context);

    }

    /**
     * 分享链接 到微信朋友圈  自定义图片
     */
    public static void shareUrlToCircleFriends(Context context, String title, String url, Bitmap bm) {
//       shareWxOrCircle(context,new SendMessageToWX.Req(),"wx548210ae36b5de58","com.tencent.mtt");
        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();

        // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间等使用
        oks.setTitle(title);
        oks.setUrl(url);
        oks.setText(url);
        oks.setImageData(bm);
        oks.setPlatform(WechatMoments.NAME);
        oks.setCallback(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

            }

            @Override
            public void onError(Platform platform, int i, Throwable throwable) {

            }

            @Override
            public void onCancel(Platform platform, int i) {

            }
        });
        oks.show(context);

    }

    /**
     * 分享链接 到微信好友  自定义图片
     */
    //TODO
    public static void shareUrlToFriends(Context context, String title, String url, Bitmap bm) {
        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();

        // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间等使用
        oks.setTitle(title);
        oks.setUrl(url);
        oks.setText(url);
        oks.setImageData(bm);
        oks.setPlatform(Wechat.NAME);
        oks.setCallback(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

            }

            @Override
            public void onError(Platform platform, int i, Throwable throwable) {

            }

            @Override
            public void onCancel(Platform platform, int i) {

            }
        });
        oks.show(context);

    }

    /**
     * 分享链接 到微信好友
     */
    public static void shareUrlToFriends(Context context, String title, String url, String imgUrl) {
        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();

        // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间等使用
        oks.setTitle(title);
        oks.setImageUrl(imgUrl);
        oks.setText(url);
        oks.setUrl(url);
        oks.setSiteUrl(imgUrl);
        oks.setPlatform(Wechat.NAME);
        oks.setCallback(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

            }

            @Override
            public void onError(Platform platform, int i, Throwable throwable) {

            }

            @Override
            public void onCancel(Platform platform, int i) {

            }
        });
        oks.show(context);

    }

    /**
     * 调用系统原生分享
     */
    public static void shareOriginal(Context context) {
        Intent share_intent = new Intent();

        share_intent.setAction(Intent.ACTION_SEND);

        share_intent.setType("text/plain");
        share_intent.putExtra(Intent.EXTRA_SUBJECT, "f分享");

        share_intent.putExtra(Intent.EXTRA_TEXT, "HI 推荐您使用一款软件:" + "http://www.baidu.com");

        share_intent = Intent.createChooser(share_intent, "分享");

        context.startActivity(share_intent);
    }
}
